<?php
session_start();
if (isset($_SESSION["account"])) {
?>
<?php require_once('common/header.php'); ?>
<?php require_once('common/sidebar.php'); ?> 
        <div class="main-content app-content mt-0">
                <div class="side-app">
            <!--占位-->
<div class="card"> </div>
<!--占位-->
                    <!-- CONTAINER -->
                    <div class="main-container container-fluid">
                
                        <!-- PAGE-HEADER -->
                        
                    <div class="row row-sm">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-header">
                                    <h3 class="card-title">订单列表</h3></h3>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-bordered text-nowrap border-bottom" id="responsive-datatable">
                                            <thead>
                                                <tr>
                                                    <th class="wd-10p border-bottom-0">订单号</th>
                                                    <th class="wd-10p border-bottom-0">商品名称</th>
                                                    <th class="wd-10p border-bottom-0">推广人</th>
                                                    <th class="wd-10p border-bottom-0">姓名</th>
                                                    <th class="wd-10p border-bottom-0">手机号</th>
                                                    <th class="wd-10p border-bottom-0">号码状态</th>
                                                    <th class="wd-10p border-bottom-0">订单状态</th>
                                                    <th class="wd-10p border-bottom-0">订单说明</th>
                                                    <th class="wd-10p border-bottom-0">下单时间</th>
                                                </tr>
                                            </thead>
                                            <tbody id="odertbody">
                                                
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                    <!-- CONTAINER CLOSED -->
               </div>
            </div>
                 <?php
        session_start();
        include_once("../untils/conn.php");
        mysqli_query($con, "set names utf8");
        
        // 获取当前正在登录的账号信息的代理
        $proxy_acc = $_SESSION["account"];
        
        // 查询proxy表中的数据
        $query = "SELECT proxy_rename_sta FROM proxy WHERE proxy_acc = '$proxy_acc'";
        $result = mysqli_query($con, $query);
        $row = mysqli_fetch_assoc($result);
        
        if ($row) {
            $proxy_rename_sta = $row['proxy_rename_sta'];
        ?>
        
        <div class="modal fade" id="modaldemo5" data-bs-backdrop="static" data-bs-keyboard="false">
            <div class="modal-dialog modal-dialog-centered text-center" role="document">
                <div class="modal-content tx-size-sm">
                    <div class="modal-body text-center p-4 pb-5">
                        <i class="icon icon-close fs-70 text-danger lh-1 my-5 d-inline-block"></i>
                        <h4 class="text-danger">警告: 您的账号未实名！</h4>
                        <p class="mg-b-20 mg-x-20">平台要求所有代理商必须实名！否则无法使用平台功能！</p>
                        <a href="profile.php" class="btn btn-primary pd-x-25">去实名</a>
                    </div>
                </div>
            </div>
        </div>
        
        
            <!--/div-->
<script src="assets/js/jquery.min.js"></script>
<script>
$(document).ready(function() {
  // 发送 Ajax 请求获取订单数据
  $.ajax({
    url: 'controller/Order.php',
    type: 'POST',
    dataType: 'json',
    success: function(data) {
      // 渲染数据到表格中
      var tableHtml = '';
      for (var i = 0; i < data.length; i++) {
        tableHtml += '<tr>';
        tableHtml += '<td>' + data[i].order_id + '</td>';
        tableHtml += '<td>' + data[i].goods_name + '</td>';
        tableHtml += '<td>' + data[i].account + '</td>';
        tableHtml += '<td>' + data[i].name + '</td>';
        tableHtml += '<td>' + data[i].phone + '</td>';

        // 根据 card_sta 显示文本
        var cardStatus = '';
        if (data[i].card_sta === '0') {
          cardStatus = '未激活';
        } else if (data[i].card_sta === '1') {
          cardStatus = '已激活';
        }
        tableHtml += '<td>' + cardStatus + '</td>';

        // 根据 order_sta 显示文本
        var orderStatus = '';
        if (data[i].order_sta === '0') {
          orderStatus = '未处理';
        } else if (data[i].order_sta === '1') {
          orderStatus = '已下单';
        } else if (data[i].order_sta === '2') {
          orderStatus = '已发货';
        } else if (data[i].order_sta === '3') {
          orderStatus = '已完成';
        }else if (data[i].order_sta === '4') {
          orderStatus = '开卡失败';
        }
        tableHtml += '<td>' + orderStatus + '</td>';

        tableHtml += '<td>' + data[i].notes + '</td>';
        tableHtml += '<td>' + data[i].order_time + '</td>';
        tableHtml += '</tr>';
      }
      $('#odertbody').html(tableHtml);
    },
    error: function(xhr, status, error) {
      console.log(error);
    }
  });
});

</script>   
<script>
    $(document).ready(function() {
        <?php
        if ($proxy_rename_sta == 0) {
            // 未实名认证
            echo '$("#modaldemo5").modal("show");';
            echo '$("#modaldemo5").modal({backdrop: "static", keyboard: false});';
        } elseif ($proxy_rename_sta == 1) {
            // 已实名认证
            echo '$("#modaldemo5").modal("hide");';
        }
        ?>
    });
</script>

<?php
} else {
    // 未找到相关数据
    // echo '数据不存在';
}
?>
 <?php require_once('common/footer.php'); ?>   
 <?php
} else {
  echo "<script>alert('登录过过期，没有权限访问该页面');location.href='login.html';</script>";
}
